import Mock from "mockjs";
// 成功
const success = {
  code: 0,
}
// 登录
Mock.mock(RegExp("/api/login"), "get", () => {
  return Mock.mock({
    ...success,
    msg: "登录成功",
    data: {
      userName: "@cname",
      avatar: "@image('100x100', '#000', '#fff', 'avatar')",
      email: "@email",
      address: "@county(true)",
      token: "@guid",
      permissions: ['*:*:*']
    }
  })
})
// 图片分类
Mock.mock(RegExp("/api/image/group"), "get", () => {
  return {
    ...success,
    "msg": "获取成功",
    "data": [
      {
        "id": 1,
        "name": "分类1",
        "children": [
          {
            "id": 2,
            "name": "分类1-1",
          },
          {
            "id": 3,
            "name": "分类1-2",
          }
        ]
      }
    ]
  }
})

// 图片列表
Mock.mock(RegExp("/api/image/list"), "get", () => {
  return Mock.mock({
    ...success,
    "msg": "获取成功",
    "data": {
      "total": "@integer(100, 1000)",
      "list|10": [
        {
          "id": "@increment(1)",
          "name": "@name",
          "path": "https://picsum.photos/id/237/200/300?@name"
        }
      ]
    }
  })
})


// 用户列表
Mock.mock(RegExp("/api/user/list"), "get", () => {
  return Mock.mock({
    ...success,
    "data": {
      "total": "@integer(100, 1000)",
      "list|10": [{
        "id|+1": 1,
        "name": "@cname",
        "descript": "@csentence(20,50)",
        "avatar": "@image('200x200', '#50B347', '#FFF', 'FastMock')",
        "email": "@email",
        "address": "@county(true)"
      }]
    }
  })
})

// 用户详情
Mock.mock(RegExp("/api/user/info"), "get", (option) => {
  let query = new URLSearchParams(option.url.split('?')[1]);

  return Mock.mock({
    ...success,
    msg: "获取成功",
    data: {
      "id": query.id,
      "name": "@cname",
      "descript": "@csentence(20,50)",
      "avatar": "@image('200x200', '#50B347', '#FFF', 'FastMock')",
      "email": "@email",
      "address": "@county(true)"
    }
  })
})

// 角色列表
Mock.mock(RegExp("/api/role/list"), "get", () => {
  return Mock.mock({
    ...success,
    "msg": "获取成功",
    "data": {
      "total": 2,
      "list": [
        {
          id: 1,
          name: '管理员',
          createTime: '2023-09-06 13:49:35',
          
        },
        {
          id: 2,
          name: '测试账号',
          createTime: '2023-09-06 13:49:35',
          
        }
      ]
    }
  })
})

// 获取菜单
Mock.mock(RegExp("/api/menu/tree"), "get", () => {
  return Mock.mock({
    ...success,
    "msg": "获取成功",
    "data": [
      {
        "id": 1,
        "name": "系统设置",
        "role": "system",
        "children": [
          {
            "id": 2,
            "name": "用户管理",
            "role": "system:user:list"
          },
          {
            "id": 3,
            "name": "角色管理",
            "role": "system:role:list"
          }
        ]
      }
    ]
  })
})